package com.longchat.controller;

import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.longchat.controller.admin.BaseController;
import com.longchat.dto.award.AwardLogInfo;
import com.longchat.dto.award.AwardResult;
import com.longchat.service.inter.award.IAwardService;
import com.longchat.utils.vo.ResultWrapper;

@Controller
@RequestMapping("/lottery")
public class LotteryController extends BaseController{
	String openid="33333333";
	@Autowired
	private IAwardService awardService;
	
	@ResponseBody
	@RequestMapping("/award/{activityid}")
	public ResultWrapper<AwardResult> award(HttpServletRequest request,@PathVariable("activityid")Integer activityid){
		openid = UUID.randomUUID().toString().replaceAll("-", "");
		return awardService.award(activityid,getOpenid(request),getNickName(request));
	}
	@ResponseBody
	@RequestMapping("/awardLog")
	public ResultWrapper<List<AwardLogInfo>> awardLog(){
		return awardService.findAwardLog(openid);
	}
	@RequestMapping("/index/{activityid}")
	public String index(Map<String,Object> data,@PathVariable("activityid")Integer activityid){
		data.put("activity",awardService.findActivity(activityid));
		data.put("result", awardService.findAllAward(activityid));
		return "/index";
	}
	
}
